package com.zmn.oms.business.impl.xno;

import com.alibaba.fastjson.JSON;
import com.zmn.common.utils.string.StringUtil;
import com.zmn.manager.mq.constant.MqTopicConsts;
import com.zmn.manager.mq.interfaces.ZmnMQSender;
import com.zmn.oms.business.interfaces.xno.OrderXnoBindBService;
import com.zmn.oms.business.interfaces.xno.OrderXnoBindService;
import com.zmn.oms.common.annotation.ZsNormalOrderWorkLog;
import com.zmn.oms.common.constant.MessageQueueTagConsts;
import com.zmn.oms.common.constant.OrderLogConsts;
import com.zmn.oms.model.dto.work.xno.XnoBindDTO;
import com.zmn.oms.model.dto.work.xno.XnoUnBindDTO;
import com.zmn.oms.services.interfaces.detail.OrderDetailService;
import com.zmn.oms.services.interfaces.work.OrderWorkService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @ClassName OrderXnoBindBServiceImpl
 * @description:
 * @author: wangyanci
 * @create: 2021-08-04 17:07
 * @Version 1.0
 **/
@Slf4j
@Service
public class OrderXnoBindBServiceImpl implements OrderXnoBindBService {

    @Autowired
    OrderWorkService orderWorkService;
    @Autowired
    OrderDetailService orderDetailService;
    @Autowired
    OrderXnoBindService orderXnoBindService;
    @Autowired
    OrderXnoBindBService orderXnoBindBService;
    @Autowired
    ZmnMQSender zmnMQSender;

    @Transactional
    @ZsNormalOrderWorkLog(type = OrderLogConsts.ORDER_LOG_TYPE_XNO_UNBIND, beforeProceed = false)
    @Override
    public void unBind(XnoUnBindDTO xnoUnBindDTO) {
        orderXnoBindService.unBind(xnoUnBindDTO);
    }

    @Transactional
    @ZsNormalOrderWorkLog(type = OrderLogConsts.ORDER_LOG_TYPE_XNO_BIND, beforeProceed = false)
    @Override
    public void bind(XnoBindDTO xnoBindDTO) {
        orderXnoBindService.bind(xnoBindDTO);
    }

    @Override
    public void sendToUnBindQueue(XnoUnBindDTO xnoUnBindDTO) {
        String key = StringUtil.getRandomsString(32);
        log.debug("com.zmn.oms.task.job.xno.OrderXnoUnBind.sendMessage key={},orderId={},workId={}", key, xnoUnBindDTO.getOrderId(), xnoUnBindDTO.getWorkId());
        zmnMQSender.send(MqTopicConsts.ZMN_TOPIC_OMS, MessageQueueTagConsts.ORDER_XNO_UNBIND, key, JSON.toJSONString(xnoUnBindDTO));
    }
}